{include file="public/header" /}
<style type="text/css">  body,
html {
    width: 100%;
    height: 100%;
    margin: 0;
    font-family: "微软雅黑";
    overflow: hidden;
}

#allmap {
    height: 100%;
    width: 100%;
    overflow: hidden;
}
.wrapper-content {
    position: fixed;
    width: 100%;
    z-index: 9999;
    top:0px;
}


</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <form class="form-horizontal" method="post">
            <div class="col-sm-12">

                <div class="col-xs-2">

                </div>
                <div class="col-xs-3">
                    <input id="address" style=" border: 1px solid #18a689;" type="text" placeholder="经纬度：无" readonly class="form-control" />
                </div>
                <div class="col-xs-4">
                    <input id="cityName"  style=" border: 1px solid #18a689;" type="text" placeholder="地址搜索" class="form-control" />
                </div>
                <div class="col-xs-2">
                    <a class="btn btn-primary" onclick="theLocation()">搜索</a>
                </div>


                </div>

                </div>
            </div>
        </form>
    </div>
</div>
<div id="allmap"></div>


<script type="text/javascript" src="http://api.map.baidu.com/api?key=&v=1.3&services=true"></script>
<script type="text/javascript">

    // 在指定容器创建地图实例并设置最大最小缩放级别
    var map = new BMap.Map("allmap", {
        minZoom: 5,
        maxZoom: 19
    });

    // 初始化地图，设置中心点和显示级别
    map.centerAndZoom(new BMap.Point(113.27812100, 23.13591100), 19);

    // 开启鼠标滚轮缩放功能，仅对PC上有效
    map.enableScrollWheelZoom(true);

    // 将控件（平移缩放控件）添加到地图上
    map.addControl(new BMap.NavigationControl());

    // 为地图增加点击事件，为input赋值
    map.addEventListener("click", function (e) {
        document.getElementById('address').value = e.point.lng+','+e.point.lat;
        window.opener.document.getElementById('latitude').value =  e.point.lat; // 赋值
        window.opener.document.getElementById('longitude').value =e.point.lng; // 赋值
        window.opener.document.getElementById('longitude_latitude').innerHTML = '经度：'+e.point.lng+'  纬度：'+e.point.lat; // 赋值
    });

    // 创建位置检索、周边检索和范围检索
    var local = new BMap.LocalSearch(map, {
        renderOptions: {
            map: map
        }
    });

    // 发起检索
    function theLocation(city='') {
        var city = document.getElementById("cityName").value;
        if (city != "") {
            var ak="5vWGU9kaMUoCmaCM6MOxCARBnOXMZMM4";
            city=encodeURIComponent(city)
            local.search(city);

            var url = 'https://api.map.baidu.com/geocoder/v2/?ak='+ak+'&output=json&address=' +city;
            $.ajax({
                type: "POST",
                url: url,
                dataType: "JSONP",
                async: false,
                success: function(data) {
                    if(parseInt(data.status) == 0) {
                        document.getElementById('address').value = data.result.location.lng+','+ data.result.location.lat;
                        window.opener.document.getElementById('latitude').value =  data.result.location.lat; // 赋值
                        window.opener.document.getElementById('longitude').value = data.result.location.lng; // 赋值
                        window.opener.document.getElementById('longitude_latitude').innerHTML = '经度：'+data.result.location.lng+'  纬度：'+data.result.location.lat; // 赋值
                    }
                }
            });
        }
    };

    // 弹出经纬度
    function submit() {
        var lat = document.getElementById('lat');
        var lng = document.getElementById('lng');
        alert("经度：" + lng.value + "\n" + "纬度：" + lat.value);
    };

    {if input('get.address')!=''}
    document.getElementById('cityName').value="{:input('get.address')}";
    theLocation();
    {/if}
</script>